package dao;

import entry.Disc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class InquiryDao {
    public static List<Disc> inquiryDao(){
        List<Disc> list = new ArrayList<>();
        PreparedStatement preparedStatement = null;
        Connection connection = null;
        ResultSet resultSet = null;
        try {
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement("select * from discs");
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                Boolean temp;
                if(resultSet.getInt(5)==1){
                    temp=true;
                }else {
                    temp=false;
                }
                list.add(new Disc(resultSet.getString(1),resultSet.getInt(2),resultSet.getString(3),resultSet.getInt(4),temp));
            }
            return list;
    }catch (Exception e){
            System.out.println("异常");
            return null;
        }finally {
            DBConnection.release(connection,preparedStatement,resultSet);
        }
    }
}
